﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// 返工返修物料拉动
    /// </summary>
    public class ReworkPartJob : IJobService
    {
        private readonly IReworkPartRepository reworkPart;

        public ReworkPartJob(IReworkPartRepository _reworkPart)
        {
            this.reworkPart = _reworkPart;
        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<MesWmsReworkPart> mesWmsReworks = reworkPart.GetReworkPartInfo();
                if (mesWmsReworks.Count <= 0)
                {
                    return "没有待返工返修物料拉动的数据！";
                }

                bool bl = reworkPart.InsertReworkPartInfo(mesWmsReworks);
                if (bl == true)
                {
                    return "待返工返修物料拉动数据同步成功！";
                }
                else
                {
                    return "待返工返修物料拉动数据同步失败！";
                }

            }
            catch (Exception ex)
            {
                LogHelper.Error("生成返工返修物料拉动错误！" + ex);
                return "生成返工返修物料拉动错误！" + ex.Message;
            }
        }
    }
}
